const Service = require('egg').Service;
class carService extends Service {
  async find(uid) {
    const sql = ``
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async addgoods(obj) {
    const sql1 = `select *from user_car WHERE userid=${obj.userid} and goods_id=${obj.goods_id}`
    const data1 = await this.app.mysql.query(sql1);
    if (data1[0]) {
      const sql = `UPDATE user_car SET goods_count=goods_count+1 WHERE userid=${obj.userid} and goods_id=${obj.goods_id}`
      const data = await this.app.mysql.query(sql);
      return data;
    } else {
      const sql = `INSERT  INTO user_car (goods_id,  userid,  goods_count) VALUES(${obj.goods_id},${obj.userid},${obj.goods_count})`
      const data = await this.app.mysql.query(sql);
      return data;
    }

  }
  async usercar(uid) {
    const sql = `select *from user_car inner join goods on user_car.goods_id=goods.goods_id WHERE user_car.userid=${uid}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getParts() {
    const sql = `SELECT * FROM goods WHERE goods_sort='配件' `
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async deletGoodscar(gid, uid) {
    const sql = `delete FROM user_car WHERE goods_id=${gid} and userid=${uid}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async serchGoods(value) {
    const sql = `SELECT *FROM goods WHERE goods_name LIKE '%${value}%'`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getCake() {
    const sql = `SELECT *FROM goods WHERE goods_sort='蛋糕'`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async getnowGoods(id) {
    const sql = `SELECT *FROM goods WHERE goods_id=${id}`
    const data = await this.app.mysql.query(sql);
    return data;
  }
  async addAddress(userid, obj) {
    const sql = `INSERT  INTO user_address  (userid,  user_name, tel,address,city) VALUES(${userid}, '${obj[0].value}', ${obj[1].value},'${obj[2].value}','${obj[3].value}')`
    const data = await this.app.mysql.query(sql);
    return data;
  }


}
module.exports = carService;